Configuration cTomcatInstaller
{
    param (

	[Parameter(Mandatory)]
	[ValidateNotNullOrEmpty()]
	[PSObject]$TomcatDefinition
    )

    Import-DscResource -ModuleName cInstaller -Name MESF_cInstallerWrapper
    Import-DscResource -ModuleName cTomcatDeployment -Name MESF_cTomcatServiceInstaller
    Import-DscResource -ModuleName xPSDesiredStateConfiguration -Name MSFT_xServiceResource


    #Log Message
    Log "cInstallerTomcatStart_$($TomcatDefinition.uniqueKey)" {
        Message = "Start cInstallerTomcat for $($TomcatDefinition.serviceName)"
    } 


    #First step install the package / archive
    cInstallerWrapper "cInstallerTomcatInstall_$($TomcatDefinition.uniqueKey)" {
        Component=$TomcatDefinition.Installers
    }

    #Tomcat instance is a windows service
    foreach($tomcatInstance in $TomcatDefinition.TomcatInstances)
    {
        
        #Ensure Tomcat service exist
        cTomcatServiceInstaller "service_$($tomcatInstance.ServiceName)"
        {
            ServiceName = $tomcatInstance.WindowsService.ServiceName
            Ensure = $tomcatInstance.Ensure
            CatalinaHome = $tomcatInstance.Catalina_Home
        }        

        #Create the registry keys
        foreach($registry in $tomcatInstance.Registry)
        {
            registry "Registry_$($registry.Key)_$($registry.ValueName)"
            {
                Key=$registry.Key
                ValueName=$registry.ValueName
                ValueData=$registry.ValueData
                ValueType=$registry.ValueType
                ensure=$registry.Ensure
            }
        }

    }

    #Log Message
    Log "cInstallerTomcatEnd_$($TomcatDefinition.uniqueKey)" {
        Message = "End cInstallerTomcat for $($TomcatDefinition.serviceName)"
    } 


}